package edu.zzu.myUtil;

import edu.zzu.mapper.PackageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
public class PackageUtil {

    @Autowired
    private PackageMapper packageMapper;

    public String produceRandomPackageId(){
        Random random=new Random();
        StringBuilder res=new StringBuilder();
        int first=random.nextInt(10);
        res.append(first==0?first+1:first);
        do{
            for(int i=0;i<12;i++){
                res.append(random.nextInt(10));
            }
        }while(packageMapper.existsWithPrimaryKey(String.valueOf(res)));

        return String.valueOf(res);

    }
}
